package com.focusai.efairy.ui.activity.global;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import com.focusai.efairy.R;
import com.focusai.efairy.utils.ActivityUtils;
import com.focusai.efairy.utils.Constants;

import java.util.Date;

public class ReloginDialogActivity extends Activity {
    private TextView txtTitle;
    private TextView txtMsg;
    private Button btnConfirm;
    private long time = 0;
    private String msg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_relogin_dialog);
        initData();
        initView();
        bindEvents();
        setDefaultValues();
    }

    private void initData() {
        if (getIntent() != null) {
            time = getIntent().getLongExtra(Constants.RE_LOGIN_TIME, System.currentTimeMillis());
            msg = getIntent().getStringExtra(Constants.RE_LOGIN_MSG);
        }
    }

    protected void initView() {
        txtTitle = (TextView) findViewById(R.id.custom_dialog_title);
        txtMsg = (TextView) findViewById(R.id.custom_dialog_message);
        btnConfirm = (Button) findViewById(R.id.custom_dialog_positive);
    }

    protected void bindEvents() {
        btnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.cleanAndStartLoginActivity(ReloginDialogActivity.this);
                finish();
            }
        });
    }


    protected void setDefaultValues() {
        Date date = new Date(time);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
//        txtMsg.setText("你的账号于" + sdf.format(date) + "在另一台设备登录，如非本人操作，请及时修改登录密码");
        if (!TextUtils.isEmpty(msg)){
            txtMsg.setText(msg);
        }else {
            txtMsg.setText(R.string.login_in_others);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
